package com.hdax.dm.service;

import com.hdax.dm.entity.user.LinkUser;
import com.hdax.dm.feign.user.LinkUserFeign;
import com.hdax.dm.vo.TicketbuyerlistVo;
import com.hdax.dm.vo.addticketbuyerVo;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class LinkUserService {

    @Autowired
    private LinkUserFeign linkUserFeign;

    public List<TicketbuyerlistVo> ticketbuyerlist(Long userId){
        List<LinkUser> linkUsers = linkUserFeign.findByUserId(userId);
        List<TicketbuyerlistVo> vos = new ArrayList<>();
        linkUsers.forEach(linkUser -> {
            TicketbuyerlistVo vo = new TicketbuyerlistVo();
            vo.setLinkId(linkUser.getId());
            vo.setCardType(linkUser.getCardType());
            vo.setIdCard(linkUser.getIdCard());
            vo.setName(linkUser.getName());
            vos.add(vo);
        });
        return vos;
    }

    public String validatebuyerexist(String idCard) {
        boolean b = linkUserFeign.validatebuyerexist(idCard);
        return b == true?null:idCard;
    }

    public String addticketbuyer(addticketbuyerVo vo) {
        LinkUser linkUser = new LinkUser();
        long l = System.currentTimeMillis();
        BeanUtils.copyProperties(vo,linkUser);
        boolean addticketbuyer = linkUserFeign.addticketbuyer(linkUser);
        return addticketbuyer == true?"添加成功":"添加失败";
    }

}
